home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr39 / inetlog.zip / INETLOG.CMD < prev    next >
OS/2 REXX Batch file  |  1995-02-12  |  11KB  |  264 lines

  1. /* INETLOG.CMD    REXX Program to extract and totalize daily and monthly        */
  2. /*             time_ons from the IBM WARP Internet Dialer CONNECT.LOG file    */
  3.  
  4. /*                         Jerry Levy,  Marblehead, MA 12 Feb 95    */
  5. /*        Please pass on comments, suggestions, problems to JLEVY@IBM.NET    */
  6. /* --------------------------------------------------------------------    */
  7. /* WHAT IT DOES:                                        */
  8. /* Deciphers the IBM WARP Internet Dialer CONNECT.LOG file.                */
  9. /* It provides daily and monthly time-on totals, providing total minutes per day        */
  10. /* for each exact time logged for each connect and for ach time rounded-up to the next    */
  11. /* whole minute.  For the monthly totals, I also included totals of time_ons rounded to    */
  12. /* to the nearest minute.                                    */
  13.                                                  
  14. /* HOW IT DOES IT:                                        */
  15. /* Looks for lines that contain the string "Disconnected after" (open your CONNECT.LOG    */
  16. /* file with the OS/2 System Editor to see this) and parses this line to extract out    */
  17. /* month and day of each connection, and does arithmetic on the times.            */
  18.  
  19. /* You should be able to adapt this for deciphering other types of .LOG files as well.    */
  20.  
  21. /* CUSTOMIZATION:                                        */
  22. /* In most cases, the only changes you may need to make are for the two expressions    */
  23. /* LOG_FILE and OUTPUT_FILE                                */
  24. /*   LOG_FILE is the path to CONNECT.LOG, where the IBM WARP Internet Dialer    */
  25. /*     logs its connection data.  This path should be fine as-is unless you installed    */
  26. /*     the internet stuff on a drive other than c:    (which I did).                */
  27. /*   OUTPUT_FILE is where we write the output.  Output is echoed to the screen    */
  28. /*     no matter what we choose here, but it scrolls by awfully fast.            */
  29.  
  30. /* Copyright Comment:  This program uses IBM's copyrighted VREXX2 ver. 1.0 Visual    */
  31. /* REXX functions for Presentation Manager, written by Richard Lam (an IBM'er).  Read     */
  32. /* LICENSE.TXT for restrictions and usage details.                        */
  33. /*                                                */
  34. /* VREXX2.ZIP can be downloaded from the IBM PCC (PC COMPANY) BBS at        */
  35. /* (919-517-0001) or any of the several OS/2 BBS's or on the internet by anonymous    */
  36. /* ftp to software.watson.ibm.net, where it can be found in the pub/os2/ews directory.    */
  37. /* It's quite nice, and free.  VREXX2.ZIP includes a 49-page manual, an on-line help    */  
  38. /* file, and demo programs.                    */
  39. /*                                                */
  40. /* INSTALLATION:                                        */
  41. /* 1.  Easy:  Place everything in this package into one folder, drag the folder onto any    */
  42. /*    one of your hard drives and run this INETLOG.CMD file by double clicking on it    */
  43. /*    or by double clicking on its shadow which you can put anywhere            */
  44. /* 2.    (Probably the right way): Copy VREXX.DLL and this INETLOG.CMD to a directory    */
  45. /*    in your PATH statement, and copy VREXX.DLL and DEVBASE.DLL to a directory    */
  46. /*    specified in the config.sys LIBPATH, e.g., into c:\os2\dll                */
  47.  
  48. /* Customize these two expressions if you need to                        */
  49.  
  50. log_file = 'c:\tcpip\etc\connect.log'    /* Complete path and filespec for the log file        */
  51. output_file = 'c:\file.$$$'        /* Wherever and whatever you want to save output to    */
  52.                     /* Don't forget the quotes if you edit this            */
  53.  
  54. /* Now we Initialize VREXX    */
  55. '@echo off'
  56. call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  57. initcode = VInit()
  58. if initcode = 'ERROR' then signal CLEANUP
  59.  
  60. signal on failure name CLEANUP
  61. signal on halt name CLEANUP
  62. signal on syntax name CLEANUP
  63. signal on error name CLEANUP
  64.  
  65. /* Load the REXXUTIL functions                        */
  66.  
  67. call rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  68. call sysloadfuncs
  69.  
  70. cr = d2c(13)            /* carriage return    */
  71. lf = d2c(10)            /* linefeed        */
  72. ff = d2c(12)            /* formfeed        */
  73.  
  74. /* Select logfile        */
  75.  
  76. do until result <> ''                    /* Don't accept a nonexistent filename    */
  77.    call VDialogPos 30, 50
  78.    button = VFileBox('Select File to Analyze', log_file, filename)
  79.    if button = 'OK' then ConnectLogFilename = filename.vstring
  80.    if button = 'CANCEL' then call CLEANUP
  81.  
  82.    call stream ConnectLogFilename, 'c', 'query exists'
  83.    if result = '' then
  84.       do
  85.          say ConnectLogFilename 'does not exist, try again!' 
  86.          call beep 1000,100
  87.        end
  88. end
  89.  
  90. /* choose file for outputting to disk    */
  91.  
  92.  
  93. do until outfile <> ''                        /* Have to enter something    */
  94.    prompt.0 = 2
  95.    prompt.1 = 'Include path and filename.  If file'
  96.    prompt.2 = 'exists it will be overwritten.'
  97.    prompt.vstring = output_file
  98.    button =  VInputBox(Select Output File, prompt, 30, 3)
  99.    if button = 'CANCEL' then call CLEANUP
  100.  
  101.    outfile = prompt.vstring
  102.    if outfile = '' then call beep 1000,100
  103. end
  104.  
  105. /* Check if the output file exists.  If it does, we overwrite it.    */
  106. /* If not, we create it                        */
  107.  
  108. call SysFileDelete prompt.vstring
  109.  
  110.  
  111. intro = 'Start of Analysis of' ConnectLogFileName Date(U) Time()||cr||lf
  112. say intro
  113. call lineout outfile, intro
  114. intro = 'Date (Logons) Minutes (exact) => minutes, each connect rounded up'
  115. say intro||cr||lf
  116. call lineout outfile, intro
  117.  
  118.                     /* Initialize         */
  119.             daycount = 0            /* Accumulate number of connects daily    */
  120.         monthcount = 0        /* Accumulate number of connects monthly    */
  121.         TimeOn = 0            /* Minutes on each conect ...            */
  122.         TimeOnRndUp = 0        /* ...rounded up to next whole minute    */
  123.         DailyTimeOn = 0        /* Accumulated minutes daily...        */
  124.         DailyTimeOnRnd = 0        /* ...which we round to nearest whole...    */
  125.         DailyTimeOnRndUp = 0    /* ...or which we round up to next whole    */
  126.         MonthlyTimeOn = 0        /* Accumulated minutes monthly...        */ 
  127.         MonthlyTimeOnRnd = 0    /* ...which we round to nearest whole...    */
  128.         MonthlyTimeOnRndUp = 0    /* ...or which we round up to next whole    */
  129.         LastMonth = 0            /* Stores 2-digit month (eg 05 for May...    */
  130.         LastDay = 0            /* ...and 2-digit day from prvious hit    */ 
  131.  
  132.         monthline = ''            /* null strings                    */
  133.         dayline = ''
  134.  
  135.         string = 'Disconnected after'        /* Word or phrase we search for in each    */
  136.                         /* line of CONNECT.LOG.  Each line    we hit    */
  137.                         /* that has it is parsed to get month, day,     */
  138.                         /* and connect time parameters        */
  139. /* Now look for the string    */
  140.  
  141. call SysFileSearch string, ConnectLogFileName, 'line.'
  142. do i = 1 to line.0
  143.     month = substr(subword(line.i, 1, 1), 1, 2)
  144.     day = substr(subword(line.i, 1, 1), 4, 2)
  145.     hrs = substr(subword(line.i, 5, 1), 1, 2)
  146.     mins = substr(subword(line.i, 5, 1), 4, 2)
  147.     secs = substr(subword(line.i, 5, 1), 7, 2)
  148.     TimeOn = (60*hrs + mins + (1/60)*secs)
  149.  
  150. /* TimeOn in minutes is rounded to 2 places.  We round up if that is not an integer */
  151.  
  152.     if trunc(TimeOn, 0)-Trunc(TimeOn, 2) = 0 then TimeOnRndUp = Trunc(TimeOn, 0)
  153.        else TimeOnRndUp = 1 + Trunc(TimeOn, 0)
  154.  
  155.     if LastMonth = 0 then
  156.        do                    /* for very first connection line    */
  157.           LastMonth = month
  158.           LastDay = day
  159.           daycount = 1
  160.           monthcount = 1
  161.           DailyTimeOn = Trunc(TimeOn, 2)
  162.           DailyTimeOnRnd = Trunc(TimeOn, 0)
  163.           DailyTimeOnRndUp = Trunc(TimeOnRndUp, 0)
  164.           MonthlyTimeOn = Trunc(TimeOn, 2)
  165.           MonthlyTimeOnRnd = Trunc(TimeOn, 0)
  166.           MonthlyTimeOnRndUp = Trunc(TimeOnRndUp, 0)
  167.        end
  168.     else NOP
  169.      
  170.     if LastMonth = month & LastDay = day & LastMonth <> 0 then            
  171.        do                        /* continue to accumulate times if same month and day    */
  172.           daycount = daycount + 1
  173.           monthcount = monthcount + 1
  174.           DailyTimeOn = DailyTimeOn + Trunc(TimeOn, 2)
  175.           DailyTimeOnRnd = DailyTimeOnRnd + Trunc(TimeOn, 0)
  176.           DailyTimeOnRndUp = DailyTimeOnRndUp + Trunc(TimeOnRndUp, 0)
  177.           MonthlyTimeOn = MonthlyTimeOn + Trunc(TimeOn, 2)
  178.           MonthlyTimeOnRnd = MonthlyTimeOnRnd + Trunc(TimeOn, 0)
  179.           MonthlyTimeOnRndUp = MonthlyTimeOnRndUp + Trunc(TimeOnRndUp, 0)
  180.        end
  181.     else NOP
  182.  
  183.                         
  184.     if LastMonth = month & LastDay <> day then        /* new day of same month    */
  185.        do
  186.  
  187.           dayline = LastMonth||'/'||LastDay '('||daycount||'X): ' format(DailyTimeOn, 4, 2) 'mins =>' format(DailyTimeOnRndUp, 4, 0)
  188.  
  189.           say dayline
  190.               call lineout outfile, dayline
  191.  
  192.            LastDay = day
  193.           daycount = 1                    /* Start counting over again */
  194.           monthcount = monthcount + 1
  195.           DailyTimeOn = Trunc(TimeOn, 2)
  196.           DailyTimeOnRnd = Trunc(TimeOn, 0)
  197.           DailyTimeOnRndUp = Trunc(TimeOnRndUp, 0)
  198.           MonthlyTimeOn = MonthlyTimeOn + Trunc(TimeOn, 2)
  199.           MonthlyTimeOnRnd = MonthlyTimeOnRnd + Trunc(TimeOn, 0)
  200.           MonthlyTimeOnRndUp = MonthlyTimeOnRndUp + Trunc(TimeOnRndUp, 0)
  201.        end
  202.         else NOP
  203.  
  204.  if LastMonth <> month & LastMonth <> 0 then
  205.        do                    /* for a new month, also by definition a new day    */
  206.  
  207.               dayline = LastMonth||'/'||LastDay '('||daycount||'X): ' format(DailyTimeOn, 4, 2) 'mins =>' format(DailyTimeOnRndUp, 4, 0)
  208.  
  209.           say dayline
  210.               call lineout outfile, dayline
  211.  
  212. /* Below, we are creating one concatenated string (with its carriage returns and linefeeds) for    */
  213. /* the monthly accumumulations and will not output this until all of the daily accumulations    */
  214. /* have been outputted.  That way all of the monthly accumulations will be together at the end    */
  215. /* of the output                                            */
  216.  
  217.           monthline = monthline||'Month'||LastMonth '('||monthcount||'x) Mins/MinsRounded/MinsRoundedUp =' MonthlyTimeOn||'/'||MonthlyTimeOnRnd||'/'||MonthlyTimeOnRndUp||cr||lf
  218.  
  219.           LastMonth = month
  220.           LastDay = day
  221.           daycount = 1
  222.           monthcount = 1
  223.           DailyTimeOn = Trunc(TimeOn, 2)
  224.           DailyTimeOnRnd = Trunc(TimeOn, 0)
  225.           DailyTimeOnRndUp = Trunc(TimeOnRndUp, 0)
  226.           MonthlyTimeOn = Trunc(TimeOn, 2)
  227.           MonthlyTimeOnRnd = Trunc(TimeOn, 0)
  228.           MonthlyTimeOnRndUp = Trunc(TimeOnRndUp, 0)
  229.        end
  230.     else NOP
  231.  
  232.      
  233. end        /* of going through all possible lines */
  234.  
  235. /* Next we output the very last daily accumulation line and then all of the monthly lines        */
  236. /* If the LastMonth and LastDay values are still zeros, then we didn't have a valid log file    */
  237.  
  238. if LastMonth = 0 & LastDay = 0 then
  239.       say 'No hits found.  This is probably not a valid connection log file'||cr||lf
  240.    else
  241.       do
  242.          dayline = LastMonth||'/'||LastDay '('||daycount||'X): ' format(DailyTimeOn, 4, 2) 'mins =>' format(DailyTimeOnRndUp, 4, 0)
  243.  
  244.          say dayline||cr||lf
  245.          call lineout outfile, dayline||cr||lf
  246.  
  247.          monthline = monthline||'Month'||LastMonth '('||monthcount||'x) Mins/MinsRounded/MinsRoundedUp ='     MonthlyTimeOn||'/'||MonthlyTimeOnRnd||'/'||MonthlyTimeOnRndUp||cr||lf
  248.  
  249.          say monthline
  250.          call lineout outfile, monthline
  251.       end
  252.  
  253. finished = 'End of analysis of' ConnectLogFilename Date(U) Time()||cr||lf
  254. say finished
  255. call lineout outfile, finished
  256.  
  257. /*    Terminate VREXX    */
  258.  
  259. CLEANUP:
  260.    call VExit
  261.  
  262.  
  263. exit
  264.